<template>
	<el-dialog title="判卷对话框" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<div style="text-align: center">
			<span style="font-weight: 600;font-size: 20px;">{{this.form.examTestTitle}}</span>
		</div>
		<el-row :gutter="24">
			<el-col :lg="12">
				<el-form-item label="参考人">{{this.form.testUserName}}</el-form-item>
			</el-col>
			<el-col :lg="12">
				<el-form-item label="参考时间">{{this.form.beginTime}}~{{this.form.endTime}}</el-form-item>
			</el-col>
		</el-row>
		<div v-for="(qList,index) in questionsList" :key="index">
			<span style="font-size: 16px;font-weight: 600">{{ index + 1 }}、{{ qList.title }}</span><span style="margin-left: 20px;color: red">{{ qList.grade }}</span>/分
			<div v-if="qList.examType=='2'">
				<div><span>解答：</span>{{ result[qList.recordId] }}</div>
				<el-input-number v-model="gradeList[qList.recordId]" placeholder="得分" :max="qList.grade" :min="0"></el-input-number>
			</div>
			<div v-else>
				<div v-for="(item,i) in qList.questionsList" :key="i" style="width: 100%;margin-left: 40px;font-size: 14px;margin-bottom: 5px">
					<el-radio v-model="result[qList.recordId]" v-if="qList.examType=='0'" :label="item.optValue" :disabled="true">{{ item.optValue }}、{{ item.childTitle }}</el-radio>
					<el-checkbox-group v-model="result[qList.recordId]" v-if="qList.examType=='1'" :disabled="true">
						<el-checkbox :label="item.optValue">{{ item.optValue }}、{{ item.childTitle }}</el-checkbox>
					</el-checkbox-group>
				</div>
			</div>
		</div>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">判 卷</el-button>
		</template>
	</el-dialog>

</template>
<script>
export default {
	emits: ['success', 'closed'],
	components: {},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg: false,
			gradeList: {},
			questionsList: [],
			result: [],
			form: {
				recordId: '',
				examTestId: '',
				examTestTitle: '',
				testUserName: '',
				beginTime: '',
				endTime: '',
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		async getExamGradeById() {
			var res = await this.$API.office.exam.getExamGradeById.get({recordId: this.form.recordId});
			if (res.code == 200) {
				this.result = JSON.parse(res.data.result)
			}
		},
		async getExamQuestionListById() {
			var res = await this.$API.office.exam.getExamQuestionListById.get({recordId: this.form.examTestId});
			if (res.code == 200) {
				this.questionsList = res.data
			}
		},
		submit() {
			this.$confirm(`确定提交判卷结果吗？`, '提示', {
				type: 'warning'
			}).then(async() => {
				let totalGrade = 0;
				this.questionsList.forEach(item => {
					if (item.examType == '2') {
						if (this.gradeList[item.recordId] != undefined) {
							totalGrade = totalGrade + this.gradeList[item.recordId];
						}
					}
				})
				this.isSaveing = true;
				var res = await this.$API.office.exam.approvalExamTest.post({recordId: this.form.recordId, totalGrade: totalGrade});
				this.isSaveing = false;
				if (res.code == 200) {
					this.$emit('success')
					this.visible = false;
					this.$message.success("判卷成功！")
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
			}).catch(() => {

			})
		},
		setData(data) {
			this.form.recordId = data.recordId;
			this.form.examTestId = data.examTestId
			this.form.examTestTitle = data.examTestTitle
			this.form.testUserName = data.testUserName
			this.form.beginTime = data.beginTime
			this.form.endTime = data.endTime
			this.getExamGradeById();
			this.getExamQuestionListById();
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
